package com.loan.controller;


import com.loan.entity.Authorize;
import com.loan.entity.Legal;
import com.loan.entity.Result;
import com.loan.mapper.LegalMapper;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author
 * @since 2024-09-28
 */
@RestController
@RequestMapping("/apply")
public class ApplyController {
    @Resource
    LegalMapper legalMapper;
    @Resource
    RedisTemplate redisTemplate;


    @RequestMapping(value = "/getLegalByUid",method = RequestMethod.POST)
    public Result getLegalByUid(){
        Object uids = redisTemplate.opsForValue().get("uid");
        Integer uid = (Integer) uids;
        Map<String,Object> columnMap=new HashMap<>();
        columnMap.put("uid",uid);

        List<Legal> legalList = legalMapper.selectByMap(columnMap);
        if (legalList.size()>0){
            Legal legal=legalList.get(0);
            Result result = new Result();
            result.setSuccess(true);
            result.setObj(legal);
            return result;
        }

        Result result = new Result();
        result.setSuccess(false);
        return result;
    }

    @RequestMapping(value = "/deleteLegalByUid",method = RequestMethod.POST)
    public Result deleteLegalByUid(){
        Object uids = redisTemplate.opsForValue().get("uid");
        Integer uid = (Integer) uids;
        Map<String,Object> columnMap=new HashMap<>();
        columnMap.put("uid",uid);

        int i = legalMapper.deleteByMap(columnMap);
        if (i>0){
            Result result = new Result();
            result.setSuccess(true);
            return result;
        }
        Result result = new Result();
        result.setSuccess(false);
        return result;
    }
}

